<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统配置修改界面')"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        .input-group{
            margin-top: 20px;
        }
    </style>

</head>
<body>

    <div class="col-sm-10" style="padding: 0 100px 0 100px;box-sizing: border-box">
        <form id="signupForm" onsubmit="return false">
            <div>
                <div class="input-group">
                    <label class="input-group-addon" id="sizing-addon1">边界审计系统地址：</label>
                    <input th:value="${fileOptions.getBigBoundaryIpAddress()}" type="text" class="form-control" name="bigBoundaryIpAddress" placeholder="边界审计系统地址" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                    <span class="input-group-addon" id="sizing-addon2">边界审计系统端口：</span>
                    <input th:value="${fileOptions.getBigBoundaryPort()}" type="text" class="form-control" name="bigBoundaryPort" placeholder="边界审计系统端口" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon3">密标地址：</span>
                <input th:value="${fileOptions.getSecretAddress()}" type="text" class="form-control" name="secretAddress" placeholder="密标地址" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon4">密标端口：</span>
                <input th:value="${fileOptions.getSecretPort()}" type="text" class="form-control" name="secretPort" placeholder="密标端口" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon5">是否上传日志：</span>
                <select class="selectpicker" name="isUploadLog">
                    <option th:selected="${fileOptions.getIsUploadLog()==1}" value="1">开启</option>
                    <option th:selected="${fileOptions.getIsUploadLog()==0}" value="0">关闭</option>
                </select>
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon6">日志类型：</span>
                <select class="selectpicker"  name="logType">
                    <option th:selected="${fileOptions.getLogType()==1}" value="1">正向导出</option>
                    <option th:selected="${fileOptions.getLogType()==2}" value="2">反向导入</option>
                </select>
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon7">单向导入系统业务IP：</span>
                <input th:value="${fileOptions.getSingleIp()}" type="text" class="form-control" name="singleIp" placeholder="单向导入系统业务IP" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon8">单向导入系统发送目录：</span>
                <input th:value="${fileOptions.getSingleChannelPath()}" type="text" class="form-control" name="singleChannelPath" placeholder="单向导入系统发送目录" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon9">审批文件落地目录：</span>
                <input th:value="${fileOptions.getFileSaveRoot()}" type="text" class="form-control" name="fileSaveRoot" placeholder="审批文件落地目录" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
            <div>
                <div class="input-group">
                <span class="input-group-addon" id="sizing-addon10">非法文件目录：</span>
                <input th:value="${fileOptions.getIllegalPath()}" type="text" class="form-control" name="illegalPath" placeholder="非法文件目录" aria-describedby="sizing-addon2" autocomplete="off">
                </div>
            </div>
        </form>
    </div>
<!-- 全局js -->
<th:block th:include="include :: common-js"/>
<!--表单验证-->
<th:block th:include="include :: validate-js"/>
<!--bootstrap-select-->
<th:block th:include="include :: bootstrap-select-js"/>

<script type="text/javascript">

    $(function () {
        let isNoNull = "不能为空!";
        let str1_15 = "长度限制为1-15个字符";
        let str1_50 = "长度限制为1-50个字符";
        let str1_4 = "长度限制为1-4个字符";
        $("#signupForm").validate({

            //debug:true,//试模式，即使验证成功也不会跳转到目标页面
            rules: {
                bigBoundaryIpAddress: {
                    required: true,
                    rangelength: [1, 15]
                },
                bigBoundaryPort: {
                    required: true,
                    rangelength: [1, 4],
                    digits:true
                },
                secretAddress: {
                    required: true,
                    rangelength: [1, 15]
                },
                secretPort: {
                    required: true,
                    rangelength: [1, 4],
                    digits:true
                },
                isUploadLog: {
                    required: true,
                    rangelength: [1, 20]
                },
                logType: {
                    required: true,
                    rangelength: [1, 20]
                },
                singleIp: {
                    required: true,
                    rangelength: [1, 15]
                },
                singleChannelPath: {
                    required: true,
                    rangelength: [1, 50]
                },
                fileSaveRoot: {
                    required: true,
                    rangelength: [1, 50]
                },
                illegalPath: {
                    required: true,
                    rangelength: [1, 50]
                },
            },
            messages: {
                bigBoundaryIpAddress: {
                    required: isNoNull,
                    rangelength: str1_15
                },
                bigBoundaryPort: {
                    required: isNoNull,
                    rangelength: str1_4,
                    digits:"请输入整数"
                },
                secretAddress: {
                    required: isNoNull,
                    rangelength: str1_15
                },
                secretPort: {
                    required: isNoNull,
                    rangelength: str1_4,
                    digits:"请输入整数"
                },
                isUploadLog: {
                    required: isNoNull,
                    rangelength: [1, 20]
                },
                logType: {
                    required: isNoNull,
                    rangelength: [1, 20]
                },
                singleIp: {
                    required: isNoNull,
                    rangelength: str1_15
                },
                singleChannelPath: {
                    required: isNoNull,
                    rangelength: str1_50
                },
                fileSaveRoot: {
                    required: isNoNull,
                    rangelength: str1_50
                },
                illegalPath: {
                    required: isNoNull,
                    rangelength: str1_50
                },

            },
            submitHandler: function () {
                let bigBoundaryIpAddress = Trim($("input[name='bigBoundaryIpAddress']").val(),"g");
                let bigBoundaryPort = Trim($("input[name='bigBoundaryPort']").val(),"g");
                let secretAddress = Trim($("input[name='secretAddress']").val(),"g");
                let secretPort = Trim($("input[name='secretPort']").val(),"g");
                let isUploadLog = Trim($("select[name='isUploadLog']").val(),"g");
                let logType = Trim($("select[name='logType']").val(),"g");
                let singleIp = Trim($("input[name='singleIp']").val(),"g");
                let singleChannelPath = Trim($("input[name='singleChannelPath']").val(),"g");
                let fileSaveRoot = Trim($("input[name='fileSaveRoot']").val(),"g");
                let illegalPath = Trim($("input[name='illegalPath']").val(),"g");

                let config = {
                    url: ctx + "SystemConfigPage/edit",
                    type: "post",
                    data: {"bigBoundaryIpAddress": bigBoundaryIpAddress,
                        "bigBoundaryPort":bigBoundaryPort,
                        "secretAddress":secretAddress,
                        "secretPort":secretPort,
                        "isUploadLog":isUploadLog,
                        "logType":logType,
                        "singleIp":singleIp,
                        "singleChannelPath":singleChannelPath,
                        "fileSaveRoot":fileSaveRoot,
                        "illegalPath":illegalPath,
                    },
                    dataType: "json",
                    success: function (data) {
                        let index = parent.layer.getFrameIndex(window.name);

                        layer.alert(data.result==-1?"操作失败!":"操作成功!", {
                            icon:data.result==-1?5:6 ,
                            title: "系统提示",
                            btn: ['确认'],
                            btnclass: ['btn btn-primary'],
                            yes:function(){
                                parent.layer.close(index);
                                parent.location.reload();
                            }
                        });
                    },
                    error: function () {

                    }
                };
                $.ajax(config);
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent());
            }
        })
    })

    function submitForm() {
        $("#signupForm").submit();
    }
    function Trim(str,is_global) {
        var result;
        result = str.replace(/(^\s+)|(\s+$)/g,"");
        if(is_global.toLowerCase()=="g") {
            result = result.replace(/\s/g,"");
        }
        return result;
    }

</script>
</body>
</html>